package com.example.project.utils;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class AntPathMatcherUtil {

    public static Boolean  getAntMatchFLag(String requestUri, String contextPath, List<String> antPatterns){
        AntPathMatcher antPathMatcher = new AntPathMatcher();

        AtomicReference<Boolean> isAllow = new AtomicReference<>(false);
        if(CollectionUtils.isEmpty(antPatterns)){
            return false;
        }
        antPatterns.forEach(allowPath->{
            if(antPathMatcher.match(contextPath+allowPath,requestUri)){
             isAllow.set(true);
            }
        });
        return isAllow.get();

    }
}
